﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

using AtletIS.Shared.Entities;

namespace AtletIS.Shared.Helpers
{
    public static class CompetitionHelper
    {
        /// <summary>
        ///  Konvertuje DataRow na CompetitionEntity
        /// </summary>
        public static CompetitionEntity ConvertToEntity(DataRow drCompetition)
        {
            CompetitionEntity comp = new CompetitionEntity();
            comp.ID = Convert.ToInt32(drCompetition["ID"]);
            
            comp.Name = drCompetition["Name"].ToString();
            comp.City = drCompetition["City"].ToString();
            comp.Organiser = drCompetition["Organiser"].ToString();

            if (drCompetition["DateFrom"] != DBNull.Value)
                comp.DateFrom = Convert.ToDateTime(drCompetition["DateFrom"]);

            if (drCompetition["DateTo"] != DBNull.Value)
                comp.DateTo = Convert.ToDateTime(drCompetition["DateTo"]);

            if (drCompetition["Deadline"] != DBNull.Value)
                comp.Deadline = Convert.ToDateTime(drCompetition["Deadline"]);

            comp.ClubsCountries = Convert.ToBoolean(drCompetition["ClubsCountries"]);

            if (drCompetition["Lanes"] != DBNull.Value)
                comp.LanesCount = Convert.ToInt32(drCompetition["Lanes"]);
            
            string lanesQuality = drCompetition["LanesQuality"].ToString();
            comp.LanesQuality = lanesQuality.Split(',');

            comp.IsActive = Convert.ToBoolean(drCompetition["Active"]);
            comp.Sync = Convert.ToBoolean(drCompetition["Sync"]);

            if (drCompetition["WebId"] == DBNull.Value)
                comp.WebId = 0;
            else
                comp.WebId = Convert.ToInt32(drCompetition["WebId"]);

            return comp;
        }
    
    
    
    
    }

}
